package com.lindroy.androidplayer.viewmodels

import androidx.lifecycle.ViewModel
import com.lindroy.androidplayer.utils.SingleLiveEvent
import com.lindroy.androidplayer.utils.mapSingle

/**
 * @author Lin
 * @date 2022/3/3
 * @function
 */
class LibraryViewModel : ViewModel() {

    private val itemClickAction = SingleLiveEvent<LibraryItemViewModel>()

    private val libraryListAction = SingleLiveEvent<List<LibraryItemViewModel>>()

    val libraryListLiveData = libraryListAction.mapSingle { it }

    val itemClickLiveData = itemClickAction.mapSingle { it }

    fun setData(data: HashMap<String, String>) {
        libraryListAction.postValue(data.map {
            LibraryItemViewModel(it.key, it.value, itemClickAction)
        })
    }

}